<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name='format-detection' content='telephone=no' />
<link rel="stylesheet" href="/assets/css/common.css" />
<link rel="stylesheet" href="/assets/css/iconfont/iconfont.css" />
<title>人车人</title><link rel="icon" href="/assets/img/titleico.ico" type="image/x-icon">
<style>
section .container .loginbox .inputbox input {
	height: 3.4rem;
	padding: .4rem 0;
	width: 100%;
	text-indent: 1rem;
}

section .container .loginbox .inputbox .getyzm {
	padding: .28rem;
	margin-right: .28rem;
	border: .5px solid #d4d4d4;
	border-radius: 3px;
	position: absolute;
	top: 12px;
	right: 11px;
}

section .container .loginbox .yzm {
	border-top: 1px solid #eaeaea;
	align-items: center;
	position: relative;
}

section .container .loginbox .password {
	border-top: 1px solid #eaeaea;
	height: 0;
}

section .container .loginbox .password.hide {
	border: 0;
	overflow: hidden;
}
</style>
</head>
<body>
	<!-- header start -->
	#@loginHead("重置密码","
	<a href='/login'>登录</a>")
	<!-- end header -->
	<section id="login">
		<div class="container">
			<div class="logo">
<!-- 				<img src="/assets/img/logo.png" width="100%" title="人车人" alt="人车人" /> -->
			</div>
			<div class="loginbox">
				<form id="form">
					<div class="inputbox yzm">
						<input type="tel" id="password" name="username" placeholder="原密码" />
						<a href="javascript:;" id="sure" class="getyzm fail">确定</a>
					</div>
					<div class="inputbox password trans hide">
						<input type="password" id="password1" name="password1"
							placeholder="新密码" /> <input type="password" id="password2"
							name="password2" placeholder="新密码" />
					</div>
				</form>
			</div>
			<div class="btnbox">
				<a href="javascript:;" id="btn" class="login fail">完成</a>
			</div>
		</div>
	</section>

	<script src="/assets/js/fastclick.min.js"></script>
	<script src="/assets/js/jquery-3.1.1.min.js"></script>
	<script src="/assets/js/xxsg.js"></script>
	<script>
        $(document).ready(function(){
        	var pw = $("#password"),
        		pw1 = $("#password1"),
        		pw2 = $("#password2"),
        		sure = $("#sure"),
        		btnDom = $("#btn"),
        		isSubmit = false;
        	sure.on("click",function(){
            	if (check3(pw)) {
            		var val = pw.val();
            		//验证原密码
            		$.ajax({
            			type:"POST",
            			url:"/login/checkOldPassword",
            			data:"password=" + val,
            			success:function(data){
            				//手机号存在
            				if(data.code=="1"){
            					isSubmit = true;
            					pw.attr("readonly","readonly");
            					pw1.parent().removeClass("hide").height(pw1.parent()[0].scrollHeight);
            				}else{
            					isSubmit = false;
            					_x.showTip(data.msg);
            					return false;
            				}
            			}
            		});
				}
            })
            btnDom.on("click",function(){
            	if (isSubmit && check3(pw1) && check3(pw2)) {
            		var form = $("#form")
            		var data = form.serialize();
            		$.ajax({
            			type: "POST",
                        url: "/login/setNewPassWord",
                        data: data,
                        success: function(data){
                        	if (data.code=="1") {
								alert("修改密码成功！")
								location.href = "/login"
							}else{
								_x.showTip(data.msg);
							}
                        }
                    })
				}
            })
        
        
            pw.blur(function(){check3(pw)});
            pw1.blur(function(){check3(pw1)});
            pw2.blur(function(){check3(pw2)});
            
            //密码判断
            function check3(el){
            	var val = el.val();
				if (_x.isEmpty(val)) {
	        		_x.showTip("请输入密码！");
	        		btnDom.addClass("fail");
					return false
				}
				
				if (/\s/g.test(val)) {
					_x.showTip("请不要输入空格！");
					btnDom.addClass("fail");
					el.val("");
					return false
				}
				if(el == pw){
					sure.removeClass("fail");
				}
				
				if(el == pw2&&pw1.val()!=pw2.val()){
					_x.showTip("新密码输入不一致！");
					btnDom.addClass("fail");
					el.val("");
					return false
				}
				
				$("#btn").removeClass("fail");
				
				return true;
            }
	        
        });
    </script>
</body>
</html>